package com.fx.huazhonghua

import android.app.PictureInPictureParams
import android.content.pm.PackageManager
import android.content.res.Configuration
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.util.Rational
import android.view.View
import android.widget.Button
import android.widget.ImageView
import android.widget.Toast
import android.widget.VideoView
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import java.net.URI

class MainActivity : AppCompatActivity() {


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val pipButton = findViewById<Button>(R.id.btn_pip)
        val vv = findViewById<VideoView>(R.id.vv)
        vv.setVideoURI(Uri.parse("http://txmov2.a.yximgs.com/upic/2020/08/26/18/BMjAyMDA4MjYxODAyMzZfMTQ4NjAyMDU0OF8zNTA1NTQ0NjE3M18xXzM=_b_B669b122df328d8b6c389caee59e513ab.mp4?tag=1-1599270586-vdg-1-efkwzf39mv-17d5eb2a2adc221e&tt=b&bp=10000"))
        vv.start()
        pipButton.setOnClickListener {
            // 进入画中画模式
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                // 设置画中画的宽高比
                val aspectRatio = Rational(16, 9)
                val params = PictureInPictureParams.Builder()
                    .setAspectRatio(aspectRatio)
                    .build()
                enterPictureInPictureMode(params)
            } else {
                Toast.makeText(this, "当前系统不支持画中画模式", Toast.LENGTH_SHORT).show()
            }
        }
    }

    override fun onPictureInPictureModeChanged(isInPictureInPictureMode: Boolean) {
        super.onPictureInPictureModeChanged(isInPictureInPictureMode)
        // 可根据需要在此处处理 UI 的变化
    }


}